import javax.swing.border.TitledBorder;

public class demo6 {
    public static void main(String[] args) {//在main函数中，从上到下执行。
        //注意三个线程的创建顺序，因为不是这三个线程不是成员变量。而是局部变量
        Thread tc=new Thread(()->{
            System.out.print("C");
        });
        Thread tb=new Thread(()->{
            try {
                tc.join();
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            System.out.print("B");
        });

        Thread ta=new Thread(()->{
            try {
                tb.join();
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            System.out.println("A");
        });

        ta.start();
        tb.start();
        tc.start();

    }
    public static void main1(String[] args) throws InterruptedException {
        Object loc1=new Object();
        Object loc2=new Object();
        Object loc3=new Object();

        Thread t1=new Thread(()->{
            try{
                synchronized (loc1){
                    loc1.wait();
                    System.out.print("C");
                    synchronized (loc2){
                        loc2.notify();
                    }
                }
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        });
        Thread t2=new Thread(()->{
            try{
                synchronized (loc2){
                    loc2.wait();
                    System.out.print("B");
                    synchronized (loc3){
                        loc3.notify();
                    }
                }
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        });
        Thread t3=new Thread(()->{
            try{
                synchronized (loc3){
                    loc3.wait();
                    System.out.println("A");
                    synchronized (loc1){
                        loc1.notify();
                    }
                }
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        });
        t1.start();
        t2.start();
        t3.start();
        Thread.sleep(1000);
        synchronized (loc1){
            loc1.notify();
        }
    }
}
